import { defineStore } from 'pinia'
import searchApi from '@/api/search'
import type { DefaultKeywordData } from '@/api/search'
interface SearchStoreData {
  defaultKeyword:DefaultKeywordData
  hotKeywordList: DefaultKeywordData[]
  hotTimeData:string[]
  categoryL1List:CategoryL1List[]
  directlyList:any
}
type CategoryL1List = {
  frontName: null
  id: number
  name: string
}
export const searchStore = defineStore('search', {
  state(): SearchStoreData {
    return {
      defaultKeyword: {
        keyword: '',
        schemeUrl: '',
        highlight: 0,
        hidden: 0,
        type: 0,
        algSort: false,
        extra: {}
      },
      hotKeywordList: [],
      hotTimeData:[],
      categoryL1List:[],
      directlyList:[]
    }
  },
  actions: {
    async getHotSearchdata_search() {
      try {
        const res = await searchApi.getHotSearch_search()
        // console.log(res)
        this.hotKeywordList = res.data.hotKeywordVOList
        this.defaultKeyword = res.data.defaultKeyword
      } catch (error) {
        console.log(error)
      }
    },
    async getSearchTime_search(params:string){
      try {
        const res = await searchApi.getSearchTime_search(params)
        // console.log(res)
        this.hotTimeData = res.data
      } catch (error) {
        console.log(error)
      }
    },
    async getSearchMainInfo(params:string){
      try {
        const res = await searchApi.getSearchMainInfo(params)
        console.log(res);
        this.categoryL1List = res.data.categoryL1List
        this.directlyList = res.data.directlyList
      } catch (error) {
        console.log(error);
        
      }
    }
  },
  getters: {}
})
